#!/bin/bash

# AMyCMS - Asterisk and MySQL Cluster Management Suite
# This script is part of the Asterisk and MySQL Cluster configuration and management suite for Debian Lenny
# Please see the README for more info
# This script installs and configures MySQL Cluster Management for Debian Lenny
# IMPORTANT!!!!
# This script is the management script, only run it on your MANAGEMENT nodes!!
#
# Copyright Phil Haddad 2009 

# IP address scheme (change to suit your cluster)

node1="192.168.70.150"
node2="192.168.70.151"
node3="192.168.70.152"
node4="192.168.70.153"
mgm1="192.168.70.162" # MySQL Cluster Management Node 

# install packages

apt-get install flex make gcc g++ libncurses5-dev sox libmysqlclient15-dev mysql-server mysql-client php5 php5-cli
# make sure we stop the mysql deamon
/etc/init.d/mysql stop

# create config.ini - adjust to suit your cluster

echo "[ndbd default]
NoOfReplicas=4

[mgm]
Hostname=$mgm1

[mysqld default]
[ndb_mgmd default]
[tcp default]

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node1
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node2
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node3
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[ndbd]
HeartbeatIntervalDbDb=600
HeartBeatIntervalDbApi=600
Hostname=$node4
DataDir=/var/lib/mysql-cluster
DataMemory=50M
IndexMemory=25M
MaxNoOfConcurrentTransactions=50
MaxNoOfConcurrentOperations=250
TimeBetweenWatchDogCheck=40000
MaxNoOfOrderedIndexes=1000
MaxNoOfTables=200
MaxNoOfAttributes=250

[mysqld]
[mysqld]
[mysqld]
[mysqld]" >> /var/lib/mysql-cluster/config.ini

# start up the NDB Management API and MySQL 
# Please note that you MUST have a management node running in order to connect
# the cluster nodes!

/etc/init.d/mysql-ndb-mgm start
/etc/init.d/mysql start

